import Vue from "vue"
import Router from "vue-router"

Vue.use(Router)


const routes = [
    {
        path: '/',
        name: 'home',
        component: () => import('../pages/home.vue'),
        redirect: 'index',
        children: [
            {
                path: 'index',
                name: 'index',
                component: () => import('../pages/index.vue'),
            },
            {
                path: 'product/:id',
                name: 'product',
                component: () => import('../pages/product.vue'),
                // component: resolve => require(['@/pages/product.vue'], resolve)
            },
            {
                path: 'detail/:id',
                name: 'detail',
                component: () => import('../pages/detail.vue'),
                // component: resolve => require(['@/pages/detail.vue'], resolve)
            },
            {
                path: 'bannerPage/:categoryId',
                name: 'bannerPage',
                component: () => import('../pages/bannerPage.vue'),
            },
        ]
    },
    {
        path: '/cart',
        name: 'cart',
        component: () => import('../pages/cart.vue'),
        // component: resolve => require(['@/pages/cart.vue'], resolve)
    },
    {
        path: '/order',
        name: 'order',
        component: () => import('../pages/order.vue'),
        // component: resolve => require(['@/pages/order.vue'], resolve),
        children: [
            {
                path: 'list',
                name: 'order-list',
                component: () => import('../pages/orderList.vue')
                // component: resolve => require(['@/pages/orderList.vue'], resolve)
            },
            {
                path: 'confirm',
                name: 'order-confirm',
                component: () => import('../pages/orderConfirm.vue')
                // component: resolve => require(['@/pages/orderConfirm.vue'], resolve)
            },
            {
                path: 'pay',
                name: 'order-pay',
                component: () => import('../pages/orderPay.vue')
                // component: resolve => require(['@/pages/orderPay.vue'], resolve)
            },
            {
                path: 'alipay',
                name: 'alipay',
                component: () => import('../pages/alipay.vue')
                // component: resolve => require(['@/pages/alipay.vue'], resolve)
            }
        ]
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('../pages/login.vue')
        // component: resolve => require(['@/pages/login.vue'], resolve)
    },
]

const router = new Router({
    mode: 'history',
    routes
})

//路由前置守卫
/*router.beforeEach((to, from, next) => {
    // document.title = to.meta.title
    next()
})*/

export default router